﻿using System;
using System.ComponentModel;
using System.Dynamic;
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Ecobee.Net
{
	public class SummaryRevision : ApiObject
	{
		private string _identifier = string.Empty;
		private string _name = string.Empty;
		private bool _connected = false;
		private Revision _thermostatRevision = new Revision();
		private Revision _alertsRevision = new Revision();
		private Revision _runtimeRevision = new Revision();

		public SummaryRevision()
			: base()
		{
			throw new Exception("Construct this object by specifying the API instance to use.");
		}

		/// <summary>
		/// 
		/// </summary>
		public SummaryRevision(Api api)
			: base(api)
		{
		}

		/// <summary>
		/// The thermostat identifier.
		/// </summary>
		[JsonProperty(PropertyName = "identifier", DefaultValueHandling = DefaultValueHandling.Ignore)]
		[DefaultValue("")]
		public string Identifier
		{
			get
			{
				return _identifier;
			}
			set
			{
				_identifier = value;
			}
		}

		/// <summary>
		/// The thermostat name, otherwise an empty field if one is not set.
		/// </summary>
		[JsonProperty(PropertyName = "name", DefaultValueHandling = DefaultValueHandling.Ignore)]
		[DefaultValue("")]
		public string Name
		{
			get
			{
				return _name;
			}
			set
			{
				_name = value;
			}
		}

		/// <summary>
		/// Whether the thermostat is currently connected to the ecobee servers.
		/// </summary>
		[JsonProperty(PropertyName = "connected", DefaultValueHandling = DefaultValueHandling.Ignore)]
		[DefaultValue(false)]
		public bool Connected
		{
			get
			{
				return _connected;
			}
			set
			{
				_connected = value;
			}
		}

		/// <summary>
		/// Current thermostat revision. This revision is incremented whenever the thermostat program, HVAC mode, 
		/// settings or configuration change.
		/// </summary>
		[JsonProperty(PropertyName = "thermostatRevision", DefaultValueHandling = DefaultValueHandling.Ignore)]
		[DefaultValueConverter(typeof(Revision), typeof(RevisionDefaultConverter), "")]
		public Revision ThermostatRevision
		{
			get
			{
				return _thermostatRevision;
			}
			set
			{
				_thermostatRevision = value;
			}
		}

		/// <summary>
		/// Current revision of the thermostat alerts. This revision is incremented whenever a new alert is issued or 
		/// an alert is modified (acknowledged or deferred).
		/// </summary>
		[JsonProperty(PropertyName = "alertsRevision", DefaultValueHandling = DefaultValueHandling.Ignore)]
		[DefaultValueConverter(typeof(Revision), typeof(RevisionDefaultConverter), "")]
		public Revision AlertsRevision
		{
			get
			{
				return _alertsRevision;
			}
			set
			{
				_alertsRevision = value;
			}
		}

		/// <summary>
		/// The current revision of the thermostat runtime settings. This revision is incremented whenever the 
		/// thermostat transmits a new status message. The thermostat does this on a 15 minute interval.
		/// </summary>
		[JsonProperty(PropertyName = "runtimeRevision", DefaultValueHandling = DefaultValueHandling.Ignore)]
		[DefaultValueConverter(typeof(Revision), typeof(RevisionDefaultConverter), "")]
		public Revision RuntimeRevision
		{
			get
			{
				return _runtimeRevision;
			}
			set
			{
				_runtimeRevision = value;
			}
		}

		protected override string OnDeserializeKeyValue(dynamic dataObject)
		{
			return dataObject.identifier;
		}

		/// <summary>
		/// Returns a string that represents the current object
		/// that can be used for display purposes.
		/// </summary>
		/// <returns>A string that represents the current object.</returns>
		public override string ToString()
		{
			return this.Name;
		}
	}
}
